﻿using Microsoft.AspNetCore.Authorization;
using Simple.Services.System;

namespace Simple.WebApi.Controllers.System
{
    [Route("api/PHotline/[action]")]
    [ApiController]
    [Authorize]
    public class PrincipalHotlineController : ControllerBase
    {
        private readonly PrincipalHotlineService _principalHotlineService;
        public PrincipalHotlineController(PrincipalHotlineService principalHotlineService)
        {
            _principalHotlineService = principalHotlineService;
        }

        /// <summary>
        /// 园长热线分页查询
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppResult> Page([FromBody] PrincipalHotlinePageInput model)
        {
            var data = await _principalHotlineService.GetPage(model);
            return AppResult.Status200OK(data: data);
        }

        /// <summary>
        /// 园长热线家长端查询
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppResult> ParentPage([FromBody] PrincipalHotlinePageInput model)
        {
            var data = await _principalHotlineService.GetPage(model, true);
            return AppResult.Status200OK(data: data);
        }

        /// <summary>
        /// 详情
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<AppResult> Get([FromQuery] IdInputModel model)
        {
            var data = await _principalHotlineService.GetAsync(model.Id);
            return AppResult.Status200OK(data: data);
        }

        /// <summary>
        /// 发布建议
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppResult> Create([FromBody] CreateOrUpdatePrincipalHotlineInput model)
        {
            await _principalHotlineService.CreateAsync(model);
            return AppResult.Status200OK("发布成功");
        }

        /// <summary>
        /// 回复
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppResult> Reply([FromBody] ReplyInput model)
        {
            await _principalHotlineService.ReplyAsync(model);
            return AppResult.Status200OK("回复成功");
        }

        /// <summary>
        /// 删除建议
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppResult> Delete([FromBody] IdInputModel models)
        {
            await _principalHotlineService.DeleteAsync(models.Id);
            return AppResult.Status200OK("删除成功");
        }

        /// <summary>
        /// 删除回复
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppResult> DeleteReply([FromBody] IdInputModel models)
        {
            await _principalHotlineService.DeletReplyAsync(models.Id);
            return AppResult.Status200OK("删除成功");
        }
    }
}
